<?php
require_once('../../../WildPack/WildPack.php');
$wp = new WildPack();
$wp->using('dataaccess');
$wp->using('mvc');
$wp->using('web');


require_once('Tester.php');
require_once('Testers.php');

//-- Class containing event handlers --
class HdClass{
  public function hdPreInvoke($server, $obj, $meth, $par) {
    if ($meth !== 'save' && $meth !== 'update') {
      return true;
    }
      
    $ses = new WpSimpleSession();
    $ses->startSession();
    if ($ses->get('auth') !== true) {
      return false;
    }
    
    return true;
  }
}

$l = new WpMemLog();
$c = new WpConnectMySQL(array(
  'location' => 'localhost/wp',
  'user' => 'wp',
  'password' => 'wp',
  'log' => $l
));

$req = new WpHttpRequest();
$res = new WpHttpResponse();
$ses = new WpSimpleSession();
$ses->startSession();

$wpds = new WpDatexServerMt($c, $l, $req, $res, $ses, 'server.php', 'wptest');

$wpds->on('preinvoke', new HdClass(), 'hdPreInvoke');
$wpds->start();